package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.LbsPoint;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.LbsPointDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2021-07-05 11:06:16
 */
public class LbsPointConverts {

    private static Logger LOG = LoggerFactory.getLogger(LbsPointConverts.class);

    public static List<LbsPointDTO> convert(List<LbsPoint> lbsPointList) {
        if (CollectionUtils.isEmpty(lbsPointList)) {
            return Collections.EMPTY_LIST;
        }

        List<LbsPointDTO> lbsPointListResult = Lists.newArrayList();
        for (LbsPoint lbsPoint : lbsPointList) {
            lbsPointListResult.add(convert(lbsPoint));
        }
        return lbsPointListResult;
    }

    public static LbsPointDTO convert(LbsPoint lbsPoint) {
        try {
            return BeanUtils.copy(lbsPoint, LbsPointDTO.class);
        } catch (Exception e) {
            LOG.error("LbsPoint到LbsPointDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsPoint到LbsPointDTO转换失败", e);
        }
    }

    public static LbsPoint convert(LbsPointDTO lbsPointDTO) {
        try {
            return BeanUtils.copy(lbsPointDTO, LbsPoint.class);
        } catch (Exception e) {
            LOG.error("LbsPointDTO到LbsPoint转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsPointDTO到LbsPoint转换失败", e);
        }
    }
}